package devtools

import (
	"context"

	"gitee.com/linxing_3/sr-core/config/source"
	"gitee.com/linxing_3/sr-core/domain"
	"gitee.com/mkwchecking/sr-admin/apps/devtools/adapter/http"
	"gitee.com/mkwchecking/sr-admin/apps/devtools/conf"
	"gitee.com/mkwchecking/sr-admin/apps/devtools/entity"
	"gitee.com/mkwchecking/sr-admin/pkg/plugins/pdatabase"

	// register cmd
	_ "gitee.com/mkwchecking/sr-admin/apps/devtools/adapter/cmd"
)

var _ domain.IDomain = (*Devtools)(nil)

func NewDevtools() domain.IDomain {
	return &Devtools{}
}

type Devtools struct {
}

// Install implements domain.IDomain.
func (d *Devtools) Install(ctx context.Context, src source.ISource) error {
	conf.SetupConfig(src)
	return http.InitHttp(ctx)
}

// BeforeStart implements domain.IDomain.
func (d *Devtools) BeforeStart(src source.ISource) error {

	if err := entity.AutoMigrate(pdatabase.MustGetDatabase()); err != nil {
		return err
	}

	return nil
}

// Start implements domain.IDomain.
func (d *Devtools) Start(ctx context.Context) error {
	return nil
}

// Stop implements domain.IDomain.
func (d *Devtools) Stop(ctx context.Context) error {
	return nil
}
